<table>
	<tbody>
		<tr>
			<th>
				<?php echo __('Languages')?>
			</th>
			<th>
				<?php echo __('Status')?>
			</th>
			<th>
				<?php echo __('Action')?>
			</th>
		</tr>
<?php
$savedLanguages = Set::combine($savedLanguages,'{n}.Language.code','{n}');
?>		
<?php foreach($languages as $code => $language){?>
	<tr>
		<td>
			<?php echo $language?>
		</td>
		<td>
			<?php 
				$status =false;
				$active = false;
				$filePath = APP.'locale'.DS.Language::getLocaleName($code).DS.'LC_MESSAGES'.DS.'default.po';
				$fileUploded = file_exists($filePath);
				$isDefault = false;
				$isSaved = false;
				if(isset($savedLanguages[$code]) )
				{
					$isSaved = true;
					$languageInfo = $savedLanguages[$code]['Language'];
					$active = $languageInfo['status'] == Language::ACTIVE;
					if($languageInfo['is_default'])
					{
						$isDefault = true;
						if($fileUploded)
						{
							$status = __("Default and file uploaded.");
						}else
						{
							$status =  __("Default and not file not uploaded.");
						}
					}
					$statusLabel = "Inactive";
					if($active)
					{
						if($fileUploded)
						{
							$status = __("Active and file uploaded.");
						}else
						{
							$status =  __("Active and file not uploaded.");
						}
					}else
					{
						if($fileUploded)
						{
							$status = __("Inactive and file uploaded.");
						}else
						{
							$status =  __("Inactive and file not uploaded.");
						}
					}
				}else
				{
					if(cr('Config.language') == $code && !isset($savedLanguages[$code]))
					{
						$active = true;
						$isDefault = true;
						if($fileUploded)
						{
							$status = __("Default by system and file uploaded. Please click on set as default to implement it correctly");
						}else
						{
							$status =  __("Default by system  and file not uploaded. Please click on set as default to implement it correctly");
						}	
					}
					else
					{
						if($fileUploded)
						{
							$status = __("Inactive and file uploaded");
						}else {
							$status =  __("Inactive");
						}
					}
				}
				
				echo $status;
			?>
		</td>
		<td>
			<?php 
					echo $html->link(__("Upload Po File"),array('action'=>"admin_uploadLanguageFile",$code));
					echo " | ";
					echo $html->link(__("Add translations"),array('action'=>"translate",$code));
					//if($active == false)
					{
						$links = array();
						if(!$isDefault || !$isSaved)
						{
							$links[] =  $html->link(__('Set As Default'),array('action'=>'admin_setAsDefault',$code),null,sprintf(__("Are you sure that you want to make %s as your default language"),$language));
						}
						if(!$active || !$isSaved)
						{
							$links[] = $html->link(__('Activate'),array('action'=>'activate',$code));
						}else 
						if(!$isDefault && $isSaved)
						{
							$links[] = $html->link(__('Deactivate'),array('action'=>'deactivate',$code));
						}
						echo " | ";
						echo implode(" | ",$links);
					}	
			?>
		</td>
	</tr>
<?php }
?>
	</tbody>
</table>